package br.edu.ufcg.ga.population;

import org.jgap.Chromosome;
import org.jgap.Configuration;
import org.jgap.Gene;
import org.jgap.IChromosome;
import org.jgap.InvalidConfigurationException;

public class SimplePopulationGenerator implements InitialPopulationGenerator {

	@Override
	public IChromosome[] createSampleChromosomes(IChromosome sampleChromosome, Configuration configuration)
			throws InvalidConfigurationException {
		IChromosome[] chromosomes = new IChromosome[configuration.getPopulationSize()];
		Gene[] samplegenes = sampleChromosome.getGenes();

		for (int i = 0; i < chromosomes.length; i++) {
			Gene[] genes = new Gene[samplegenes.length];

			for (int k = 0; k < genes.length; k++) {
				genes[k] = samplegenes[k].newGene();
				genes[k].setAllele(samplegenes[k].getAllele());
			}
			chromosomes[i] = new Chromosome(configuration, genes);
		}
		return chromosomes;
	}

}
